package com.encyclopedia.controller;

import com.encyclopedia.domain.PlantCrop;
import com.encyclopedia.domain.PlantCropRelation;
import com.encyclopedia.domain.vo.PlantCropRelationVo;
import com.encyclopedia.result.JsonRequest;
import com.encyclopedia.service.PlantCropRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author MaLiang
 * @version 1.0
 * @date 2024-05-03 16:11
 */
@RestController
@RequestMapping("/admin/relation")
public class PlantCropRelationController {


    @Autowired
    private PlantCropRelationService plantCropService;


    // 获取所有信息
    @GetMapping("/list")
    public JsonRequest getInfo(PlantCropRelationVo plantCropRelationVo){

        return JsonRequest.success(plantCropService.getInfo(plantCropRelationVo));
    }


    @GetMapping("/crop")
    public JsonRequest getCrop(PlantCrop plantCrop){
        return JsonRequest.success(plantCropService.getCropInfo(plantCrop));
    }

    /**
     * 新增
     * @param plantCropRelation
     * @return
     */
    @PostMapping
    public JsonRequest insertCropRelation(@RequestBody PlantCropRelation plantCropRelation){
        return JsonRequest.success(plantCropService.insertCropRelation(plantCropRelation));
    }
    @PutMapping
    public JsonRequest updateCropRelation(@RequestBody PlantCropRelation plantCropRelation){
        return JsonRequest.success(plantCropService.updateCropRelation(plantCropRelation));
    }

    @DeleteMapping("/{id}")
    public JsonRequest deleteCropRelation(@PathVariable("id") Integer id){
        return JsonRequest.success(plantCropService.deleteCropRelation(id));
    }

    @GetMapping("/{id}")
    public JsonRequest selectCropRelation(@PathVariable("id") Integer id){
        return JsonRequest.success(plantCropService.selectCropRelation(id));
    }

}
